<?php  
//分页公共函数
 function page($baseUrl,$table,$p, $pagenum='10')  //接受参数
{
		$sql = 'select count(*) as total from '.$table;
		$query = mysql_query($sql);
		$result = mysql_fetch_assoc($query);
		$total = $result['total'];
		$totalnum = ceil($total/$pagenum);//最大的总页整数
		//print_r($totalnum);exit;
		
		$con = '' ;//分页的连接
		if($p>1){
			$con.='<a href="'.$baseUrl.'?p=1">首页</a>';
			$con.='<a href="'.$baseUrl.'?p='.($p-1).'">上一页</a>';
		}
		$start = ($p - 2);
		$end = ($p + 2);
		if($start < 1){
			$end = $end - $start + 1;
			$start = 1;
		}
		if($end > $totalnum){
			$start = $totalnum - 4;
			if($start < 1){
				$start = 1;
			}
			$end = $totalnum;
		}
		
		$end = $totalnum;
		for($i = $start; $i <= $end; $i++)   //for循环出页数的a标签
		{
			if($p == $i)       //如果$i=当前页
			{
				$con .= '<a href="'.$baseUrl.'"?p='.$i.'" class="number current" title="'.$i.'">'.$i.'</a>';
			}else
			{
				$con .= '<a href="'.$baseUrl.'?p='.$i.'" class="number" title="'.$i.'">'.$i.'</a>';
			}
			
		}
		if($p != $totalnum){
			$con .= '<a href="'.$baseUrl.'?p='.($p+1).'" >下一页</a>';
			$con .= '<a href="'.$baseUrl.'?p='.$totalnum.'" >尾页</a>';
		}
		//分页变量为自定义字符串
		
		return $con;  //return 分页的变量
		
}
function upload($file){
	//print_r($file);exit;
	$type = array(
			'image/jpeg'=>'.jpg',
			'image/bmp'=>'.bmp',
			'image/png'=>'.png',
		);
		$typeName = $type[$file['type']];
	
	$year = date('Y',time());
	$basePath = '../uploads/'.$year;
	if(!is_dir($basePath)){
		mkdir($basePath,0777);//创建../uploads/2012 文件夹，权限是777
	}
	$month = date('m',time());
	$basePath = $basePath.DIRECTORY_SEPARATOR.$month;
	if(!is_dir($basePath)){
		mkdir($basePath,0777);//创建../uploads/2012 文件夹，权限是777
	}
	$day = date('d',time());
	$basePath = $basePath.DIRECTORY_SEPARATOR.$day;
	if(!is_dir($basePath)){
		mkdir($basePath,0777);//创建../uploads/2012 文件夹，权限是777
	}
	$fileName='';
	$fileName .= $year.'/'.$month.'/'.$day.'/';
	$fileName .= time().mt_rand(1000,9999).$typeName;
	move_uploaded_file($file['tmp_name'],'../uploads/'.$fileName);
	return $fileName;
}
?>
